package Vue;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.util.Observable;
import java.util.Observer;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JProgressBar;
import javax.swing.JTabbedPane;

import Modele.MonteCarloSimulation;

import java.util.ArrayList;

public class Fenetre extends JFrame implements Observer{
	private static JComboBox combo=new JComboBox();
	private static JComboBox combo2=new JComboBox();
	private JLabel JLresult;

	private JTabbedPane onglet;
	private JProgressBar bar;
	private JButton boutonGO = new JButton("Go");
	private JButton boutonGO2= new JButton("Go2");
	private JButton bouton2 = new JButton("Stop");
	private JLabel label = new JLabel("     Selectionnez votre option :");
	private JLabel label2 = new JLabel("     Selectionnez votre option :");
	private JLabel label3 = new JLabel("     Modifier les valeurs par defaults :");
	private JLabel label4 = new JLabel(" ");
	private JLabel label5 = new JLabel("      Resultat: ");
	private JPanel pan = new JPanel(); 
	private JPanel panMono=new JPanel(new GridLayout(4, 3));
	private JPanel panMulti= new JPanel();
	private MonteCarloSimulation mcs=new MonteCarloSimulation() ;
	private JButton boutonPlus=new JButton("modifier");
	private String resu;
	 
	public Fenetre(){
		
		mcs.addObserver(this);
		bar=new JProgressBar();
		bar.setMaximum(500);
		bar.setMinimum(0);
		bar.setStringPainted(true);
		/*
		for(int val=0; val<500; val++){
		bar.setValue(val);}*/
		// creation de plusieur onglet
		
		onglet=new JTabbedPane();
		onglet.add("MonoThread",panMono);
		onglet.add("MultiThread",panMulti);
		
		combo.addItem("call");
		combo.addItem("putt");
		combo.setForeground(Color.blue);
		combo2.addItem("Simulation 1");
		combo2.addItem("Simulation 2");
		combo2.addItem("Simulation 3");
		combo2.addItem("Simulation 4");
		combo2.addItem("Simulation 5");
		
		//mcs.addObserver(this);
	  // JLresult.add((String)(mcs.calcule(combo.getSelectedItem().toString()));
		
		JLresult=new JLabel("0");
	//MONOTHREAD
		panMono.add(label);
		panMono.add(combo);
		panMono.add(boutonGO);
		panMono.add(label2);
		panMono.add(combo2);
		panMono.add(boutonGO2);
		panMono.add(label3);
		panMono.add(boutonPlus);
		panMono.add(label4);
		panMono.add(label5);
		panMono.add(JLresult);
		panMono.add(bar);
		
		this.setContentPane(pan);
		this.getContentPane().add(onglet);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setBounds(0, 0, 750, 200);
		this.setLocationRelativeTo(null);
		this.setTitle("MonteCarlo");
		this.setVisible(true);	
	}
	
	public void comboListener(ActionListener listenForCalcButton){
		combo.addActionListener(listenForCalcButton);
	}
	
	public void boutonGOListener(ActionListener listenForCalcButton){
		boutonGO.addActionListener(listenForCalcButton);
	}
	public void boutonGO2Listener(ActionListener listenForCalcButton){
		boutonGO2.addActionListener(listenForCalcButton);
	}
	public void boutonPlusListener(ActionListener listenForCalcButton){
		boutonPlus.addActionListener(listenForCalcButton);
	}  
	
	public static JComboBox getCombo() {
		return combo;
	}

	public void setCombo(JComboBox combo) {
		this.combo = combo;
	}
	
	public static JComboBox getCombo2() {
		return combo2;
	}

	public void setCombo2(JComboBox combo2) {
		this.combo2 = combo2;
	}
	
	public JLabel getJLresult() {
		return JLresult;
	}

	public void setJLresult(JLabel jLresult) {
		JLresult = jLresult;
	}
	

	@Override
	public void update(Observable o, Object arg) {
		Double dd = (Double)arg;
		System.out.println("OK "+dd );
		JLresult.setText(arg.toString());
		
	}
}
